package org.jwcloud.project.module.zx.matClient.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.jwcloud.project.module.zx.baseManager.service.repository.MatBaseManagerRepository;
import org.jwcloud.project.module.zx.common.FmtUtil;
import org.jwcloud.project.module.zx.common.Resp;
import org.jwcloud.project.module.zx.common.repository.RptCommonRepository;
import org.jwcloud.project.module.zx.common.service.RptUtService;
import org.jwcloud.project.module.zx.matClient.service.MatClientService;
import org.jwcloud.project.module.zx.matClient.service.MatSystemService;
import org.jwcloud.project.module.zx.matClient.service.repository.MatClientRepository;
import org.jwcloud.project.module.zx.workTime.service.repository.MatWorkTimeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.jw.mid.mm.comm.common.controller.BaseController;
import com.jw.mid.mm.comm.common.controller.CrudController;
import com.jw.mid.mm.comm.common.json.Response;
import com.jw.mid.mm.comm.common.pagination.ListBounds;
import com.jw.mid.mm.comm.common.pagination.ListSlice;
import com.jw.mid.mm.comm.common.pagination.PageListSlice;
import com.jw.mid.mm.comm.common.pagination.Pagination;
import com.jw.mid.mm.comm.common.service.CrudService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

//@Api(value = "API - Controlle",
//description = "客户端", tags = "client")
//@RestController
//@Transactional
//@RequestMapping("/rest/mat/client")
public class MatClientController extends BaseController{
	
	@Autowired
	public RptCommonRepository rptCommonRepository;
	
	@Autowired
	public MatBaseManagerRepository matBaseManagerRepository;
	@Autowired
	public MatWorkTimeRepository matWorkTimeRepository;
	@Autowired
	public MatClientService matClientService;
	@Autowired
	public MatSystemService matSystemService;
	@Autowired
	public MatClientRepository matClientRepository;
	
	@Autowired
    public RptUtService rptUtService;
	
	@RequestMapping("/view1")
	public ModelAndView testView(String param, ModelAndView model) {
		model.setViewName("test/client/view1.html");
		return model;
	}
	@RequestMapping("/view2")
	public ModelAndView view2(String param, ModelAndView model) {
		model.setViewName("test/client/view2.html");
		return model;
	}
	@RequestMapping("/view3")
	public ModelAndView view3(String param, ModelAndView model) {
		model.setViewName("test/client/view3.html");
		return model;
	}
	
	@GetMapping("queryWorkList")
	@Deprecated
    @ApiOperation(value = "查询工作信息--/moon/rest/money/baseManager/queryWorkList", notes = "")
    @ApiImplicitParams({
    })
    public Resp queryWorkList(
    		@RequestParam(required = false) Map<String,String> param
    		){
		return Resp.success(this.matBaseManagerRepository.queryWorkList(param));
    }
	
	@PostMapping("saveSb")
    @ApiOperation(value = "保存申报", notes = "")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "xqmc", value = "小区名称", required = true, dataType = "string", paramType = "query"),
    	@ApiImplicitParam(name = "sbdw", value = "申报单位", required = true, dataType = "string", paramType = "query"),
    	@ApiImplicitParam(name = "wxxm", value = "维修项目", required = true, dataType = "string", paramType = "query"),
    	@ApiImplicitParam(name = "tswxxm", value = "特殊维修项目 ", required = false, dataType = "list", paramType = "query"),
    	@ApiImplicitParam(name = "budget_money", value = "工程预算金额（元）", required = true, dataType = "string", paramType = "query"),
    	@ApiImplicitParam(name = "gap_money", value = "资金缺口（元）", required = false, dataType = "string", paramType = "query"),
    	@ApiImplicitParam(name = "sbr_name", value = "申报人姓名", required = true, dataType = "string", paramType = "query"),
    	@ApiImplicitParam(name = "id_card", value = "身份证号", required = true, dataType = "string", paramType = "query"),
    	@ApiImplicitParam(name = "sbr_phone", value = "申报人联系电话", required = true, dataType = "string", paramType = "query"),
    	
    })
    public Resp saveSb(
    		@RequestBody(required = false) Map<String, Object> param
    		){
		String flag = FmtUtil.nullRes(param
				, "xqmc", "小区名称"
				, "sbdw", "申报单位"
				, "wxxm", "维修项目"
				, "budget_money", "工程预算金额（元）"
				, "sbr_name", "申报人姓名"
				, "id_card", "身份证号"
				, "sbr_phone", "申报人联系电话");
		if(!StringUtils.isEmpty(flag)) 
			return Resp.error(flag);
		
		return this.matClientService.saveSb(param);
    }
	
	@PostMapping("queryItemList_client")
    @ApiOperation(value = "查询要件--客户端", notes = "")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "query_type", value = "例：['sq', 'dt_flag']; sq申报 yfk预付款 js结算  特殊维修项目 dt_flag电梯 xf_flag消防 gsgdgq_flag供水、供电、供气", required = false, dataType = "list", paramType = "query"),
    })
    public Resp queryItemList_client(
    		@RequestParam(required = false) Map<String, Object> param
    		){
		return this.matClientService.queryItemList_client(param);
    }
	
	@GetMapping("toYfk")
    @ApiOperation(value = "进入预付款页面   返回主信息+校验信息（最后写）", notes = "")
    @ApiImplicitParams({
    })
    public Resp toYfk(
    		@RequestParam(required = false) Map<String,String> param
    		){
		Map res = new HashMap();
		res.put("is_ok", "yes/no");
		res.put("check_msg", "......");
		res.put("data", new HashMap());
		return Resp.success(res);
    }
	
	
	
//	@GetMapping("checkYfk")
//    @ApiOperation(value = "预付款校验", notes = "")
//    @ApiImplicitParams({
//    	@ApiImplicitParam(name = "yw_code", value = "业务编码", required = false, dataType = "string", paramType = "query"),
//    	@ApiImplicitParam(name = "xqmc", value = "小区名称", required = false, dataType = "string", paramType = "query"),
//    	@ApiImplicitParam(name = "wxxm", value = "维修项目", required = false, dataType = "string", paramType = "query"),
//    	@ApiImplicitParam(name = "id", value = "id", required = false, dataType = "string", paramType = "query"),
//    	
//    	@ApiImplicitParam(name = "queryType", value = "yw_code按业务编码查 by_name按小区名称、维修项目", required = false, dataType = "string", paramType = "query"),
//    	
//    })
//    public Resp checkYfk(
//    		@RequestParam(required = false) Map<String,String> param
//    		){
//		
//		this.matClientRepository.checkYfk(param);
//		
//		return null;
//    }
	
}